<template>
  <el-cascader
    v-model="modelValue"
    :props="{emitPath:false,value:'id'}"
    :options="depList"
    v-bind="$attrs"
    v-on="$listeners"
  />
</template>

<script>
import UpmsDepApi from '@/api/upms/dep'
import { pidToChildren } from '@/utils/tree'
export default {
  name: 'UpmsDepCascader',
  props: {
    value: {
      required: false,
      type: [Array, String],
      default: undefined
    },
    depPidList: {
      required: false,
      type: Array,
      default: () => ([])
    }
  },
  data() {
    return {
      depList: []
    }
  },
  computed: {
    modelValue: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      }
    },
    depPidQueryList: {
      get() {
        return this.depPidList
      },
      set(val) {
        this.$emit('update:depPidList', val)
      }
    }
  },
  mounted() {
    this.getDepList()
  },
  methods: {
    getDepList() {
      UpmsDepApi.page({
        baseParams: {},
        sort: 'seq asc'
      }).then(({ data }) => {
        this.depPidQueryList = data
        this.depList = pidToChildren(data, {})
      })
    }
  }
}
</script>

<style>

</style>
